﻿let pi = 3.1416;
let g = 9.8;
////左边全局变量
///left left
let leftIpt = document.querySelector("#jiasuTime").querySelectorAll("input");
let leftBtn = document.querySelector("#jiasuTime").querySelector("button");
////
let centerIpt = document.querySelector("#zhongjian1").querySelectorAll("input");
////
let rightBtn = document.querySelector("#dianjiSpeed").querySelector("button");
let rightIpt = document.querySelector("#dianjiSpeed").querySelectorAll("input");
////加速时间t0
let t = "";///定位时间
let t0 = "";////加减速时间
window.addEventListener("load", function () {
    leftBtn.disabled = true;
})
window.addEventListener('input', function () {
    if (!(leftIpt[0].value == "" || leftIpt[1].value == "" )) {
        leftBtn.disabled = false;
    }
    else {
        leftBtn.disabled = true;
    }
})
leftBtn.addEventListener("click", function () {
    t = parseFloat(leftIpt[0].value);
    t0 = t * parseFloat(leftIpt[1].value)/100;
    leftIpt[2].value = t0;
    centerIpt[0].value = t0;
})
//////电机转速
window.addEventListener("load", function () {
    rightBtn.disabled = true;
})
window.addEventListener('input', function () {
    if (!(rightIpt[0].value == "" || rightIpt[1].value == "")) {
        rightBtn.disabled = false;
    }
    else {
        rightBtn.disabled = true;
    }
})
let βG ///减速机输出轴角加速度
let N;////减速机输出轴最大转速
let βm = "";////电机轴角加速度
let i;////减速机减速比
rightBtn.addEventListener("click", function () {
     i = parseFloat(rightIpt[1].value)
    βG = ((parseFloat(rightIpt[0].value) * pi) / 180) / (t0*(t - t0));
    N = (βG * t0 * 60) / (2 * pi);
    βm = βG * i;
    rightIpt[2].value = N * i;
    /////高亮显示
    let g = document.querySelector("#g");
    let n = document.querySelector("#n");
    let m = document.querySelector("#m");
    g.style.color = "red";
    n.style.color = "red";
    m.style.color = "red";
    centerIpt[1].value = βG;
    centerIpt[2].value = N;
    centerIpt[3].value = βm;
    rightCenterIpt[0].value = βm;
})

/////右边全局变量
///left
let rightLeftIpt = document.querySelector("#taiguanliang").querySelectorAll("input");
let rightLeftBtn = document.querySelector("#taiguanliang").querySelector("button");
let rightLeftIpt2 = document.querySelector("#wuguanliang").querySelectorAll("input");
let rightLeftBtn2 = document.querySelector("#wuguanliang").querySelector("button");
///
let rightLeftIpt3 = document.querySelector('#wuzhiliang').querySelectorAll("input")
let rightLeftBtn3 = document.querySelector("#wuzhiliang").querySelector("button");
///
let rightLeftIpt4 = document.querySelector("#wuguanliang2").querySelectorAll("input");
let rightLeftBtn4 = document.querySelector("#wuguanliang2").querySelector("button");
////right center
let rightCenterIpt = document.querySelector("#zhongjian2").querySelectorAll("input");
///right left 
let rightRightBtn1 = document.querySelector("#jiasuzhuanju").querySelector("button");
let rightRightIpt1 = document.querySelector("#jiasuzhuanju").querySelectorAll("input");
let rightRightBtn = document.querySelector("#bixuzhuanju").querySelector("button");
let rightRightIpt = document.querySelector("#bixuzhuanju").querySelectorAll("input");
let rightRightIpt2 = document.querySelector("#guanliangbi").querySelectorAll("input");
///工作台的惯量JT
window.addEventListener("load", function () {
    rightLeftBtn.disabled = true;
})
window.addEventListener('input', function () {
    if (!(rightLeftIpt[0].value == "" || rightLeftIpt[1].value == "" || rightLeftIpt[2].value == "")) {
        rightLeftBtn.disabled = false;
    }
    else {
        rightLeftBtn.disabled = true;
    }
})
let JT;////工作台惯量
let ρ = "";/////
rightLeftBtn.addEventListener("click", function () {
    ρ = parseFloat(rightLeftIpt[0].value)
    JT = (pi * ρ * parseFloat(rightLeftIpt[1].value) * Math.pow(parseFloat(rightLeftIpt[2].value), 4)) / 32;
    rightLeftIpt[3].value = JT;

})
/////工作物的惯量JW1
let JW1 = "";
rightLeftIpt2[0].addEventListener("input", function () {
    if (ρ == "") {
        swal("请先计算工作台惯量JT的值");
        rightLeftIpt2[0].value = "";
        return ;
    }
})
window.addEventListener("load", function () {
    rightLeftBtn2.disabled = true;
})
window.addEventListener('input', function () {
        if (!(rightLeftIpt2[0].value == "" || rightLeftIpt2[1].value == "")) {
            rightLeftBtn2.disabled = false;
        }
        else {
            rightLeftBtn2.disabled = true;
        }
    })
rightLeftBtn2.addEventListener("click", function () {
        JW1 = (pi * ρ * parseFloat(rightLeftIpt2[0].value) * Math.pow(parseFloat(rightLeftIpt2[1].value), 4)) / 32;
        rightLeftIpt2[2].value = JW1;
    })
/////工作物质量
let mW;///工作物质量
rightLeftIpt3[0].addEventListener("input", function () {
        if (ρ == "") {
            swal("请先计算工作台惯量JT的值");
            rightLeftIpt3[0].value = "";
            return;
        }
    })
window.addEventListener("load", function () {
        rightLeftBtn3.disabled = true;
    })
window.addEventListener('input', function () {
        if (!(rightLeftIpt3[0].value == "" || rightLeftIpt3[1].value == "")) {
            rightLeftBtn3.disabled = false;
        }
        else {
            rightLeftBtn3.disabled = true;
        }
    })
rightLeftBtn3.addEventListener("click", function () {
    mW = (pi * ρ * parseFloat(rightLeftIpt3[0].value) * Math.pow(parseFloat(rightLeftIpt3[1].value), 2)) / 4;
    rightLeftIpt3[2].value = mW
})
/////工作物的惯量JW
let JL = "";///全负载惯量
let JW;
if (JW1 == "") { JW1 = 0 }
window.addEventListener("load", function () {
    rightLeftBtn4.disabled = true;
})
window.addEventListener("input", function () {
    if (!(rightLeftIpt4[0].value == "" || rightLeftIpt4[1].value == "")) {
        rightLeftBtn4.disabled = false;
    }
    else {
        rightLeftBtn4.disabled = true;
    }
})
rightLeftBtn4.addEventListener("click", function () {
    JW = parseFloat(rightLeftIpt4[0].value) * (JW1 + mW * Math.pow(rightLeftIpt4[1].value, 2));
    rightLeftIpt4[2].value = JW;
    ///高亮显示
    let jl = document.querySelector("#jl");
    jl.style.color = "red";
    JL = JT + JW;
    rightCenterIpt[1].value = JL;
})
//////加速转矩
let TS = ""////
let JLM;///负载折算到电机轴上的惯量
let JM;////电机惯量
window.addEventListener("load", function () {
    rightRightBtn1.disabled = true;
})
window.addEventListener("input", function () {
    if (!(rightRightIpt1[0].value == "" || rightRightIpt1[1].value == "")) {
        rightRightBtn1.disabled = false;
    }
    else {
        rightRightBtn1.disabled = true;
    }
})
rightRightIpt1[0].addEventListener("input", function () {
    if (βm == "" && JL =="") {
        swal("请先计算电机转速Nm、工作物惯量JW的值");
        rightRightIpt1[0].value = "";
        return;
    }
    if (βm == "") {
        swal("请先计算电机转速Nm的值");
        rightRightIpt1[0].value = "";
        return;
    }
    if ( JL == "") {
        swal("工作物惯量JW的值");
        rightRightIpt1[0].value = "";
        return;
    }
    
})
rightRightBtn1.addEventListener("click", function () {
    JLM = JL / (i * i);
    rightCenterIpt[2].value = JLM;/////中间值显示
    JM = parseFloat(rightRightIpt1[0].value)
    TS = (JLM + JM) * βm / parseFloat(rightRightIpt1[1].value)
    rightRightIpt1[2].value = TS;
    ////高亮显示
    let jlm = document.querySelector("#jlm");
    jlm.style.color = "red";
    /////惯量比
    rightRightIpt2[0].value = (JL / (i * i)) / JM;
})
////必须转矩
window.addEventListener("load", function () {
    rightRightBtn.disabled = true;
})
window.addEventListener("input", function () {
    if (!(rightRightIpt[0].value == "")) {
        rightRightBtn.disabled = false;
    }
    else {
        rightRightBtn.disabled = true;
    }
})
rightRightIpt[0].addEventListener("input", function () {
    if (TS == "") {
        swal("请先计算加速转矩TS的值");
        rightRightIpt[0].value = "";
        return;
    }
})
rightRightBtn.addEventListener("click", function () {
    rightRightIpt[1].value = TS * parseFloat(rightRightIpt[0].value)
})
////